//封装本地存储存储数据与读取数据方法
import type{reqLoginData,ReqfriendsData,friendsData} from '@/types/type'
//存储数据
export const SET_TOKEN = (token: string) => {
  localStorage.setItem('TOKEN', token)
}
export const SET_USERID = (userId: string) => {
  localStorage.setItem('USERID', userId)
}
export const SET_USERNAME = (username: string) => {
  localStorage.setItem('USERNAME', username)
}
export const SET_AVATAR = (avatar: string) => {
  localStorage.setItem('AVATAR', avatar)
}
export const SET_FRIENDS = (friendsList: friendsData) => {
  localStorage.setItem('FRIENDSLIST', JSON.stringify(friendsList));
}
//本地存储获取数据
export const GET_TOKEN = () => {
  return localStorage.getItem('TOKEN')
}
export const GET_USERID = () => {
  return localStorage.getItem('USERID')
}
export const GET_USERNAME = () => {
  return localStorage.getItem('USERNAME')
}
export const GET_AVATAR = () => {
  return localStorage.getItem('AVATAR')
}
export const GET_FRIENDS=()=>{
  const storedFriendsList = localStorage.getItem('FRIENDSLIST');
  return  storedFriendsList ? JSON.parse(storedFriendsList) : [];
}
//本地存储删除数据方法
export const REMOVE_TOKEN = () => {
  localStorage.removeItem('TOKEN')
}
export const REMOVE_USERID = () => {
  localStorage.removeItem('USERID ')
}
export const REMOVE_USERNAME = () => {
  localStorage.removeItem('USERNAME')
}
export const REMOVE_AVATAR = () => {
  localStorage.removeItem('AVATAR')
}
export const REMOVE_FRIENDS = () => {
  localStorage.removeItem('FRIENDSLIST')
}